cd "C:\Users\gilbe\Dropbox\EnergyImpactsAggregationBias\HannahPoverty\Poverty_Files_May2023"

clear
import delimited "all.csv", delim(",") varn(1)
gen t = _n

gen event_time = t-7
tsset event_time

foreach var of varlist sd* {
	gen `var'2 = `var'*`var'
}

foreach var of varlist b* sd_all_emp_trt2-sd_collegec_inc_gw2 {
	mkmat `var', matrix(`var')
	matrix `var' = `var''
	matrix colnames `var' = pre6 pre5 pre4 pre3 pre2 pre1 tau0 tau1 tau2 tau3 tau4 tau5 tau6
	matrix rownames `var' = r1
}


cd "C:\Users\gilbe\Dropbox\EnergyImpactsAggregationBias\JAEREFinal"

/* Figures 2 and 3: pairwise comparison individual to county */

* Figure 2: all workers, employment	
event_plot b_all_emp_trt#sd_all_emp_trt2 b_allc_emp_trt#sd_allc_emp_trt2, ///
		stub_lag(tau# tau# tau# tau#  tau# tau# L#event) ///
		stub_lead(pre# pre# pre# pre# pre# pre# F#event) plottype(scatter) ///
		ciplottype(rcap) together perturb(-0.325(0.13)0.325) trimlead(6) ///
		noautolegend ///
	lag_opt1(msymbol(S) color(black)) lag_ci_opt1(color(black)) ///
	lag_opt2(msymbol(O) color(gs10)) lag_ci_opt2(color(gs10)) ///
		graph_opt(title("All Workers: % Change in Employment", size(medlarge)) ///
		xtitle("Years since wind project operation begins") xlabel(-6(1)6)  ///
		legend(order(1 "Worker-Level" 3 "County-Level") rows(1) region(style(none))) ///
		xline(-0.5, lcolor(gs8) lpattern(dash)) yline(0, lcolor(gs8)) graphregion(color(white)) bgcolor(white) ylabel(, angle(horizontal))  ///
	)	
graph save all_wrk_cty_emp2, replace
graph export all_wrk_cty_emp2.pdf, replace
graph export all_wrk_cty_emp2.png, replace

* Figure 3: all workers, earnings
event_plot b_all_inc_trt#sd_all_inc_trt2 b_allc_inc_trt#sd_allc_inc_trt2, ///
		stub_lag(tau# tau# tau# tau#  tau# tau# L#event) ///
		stub_lead(pre# pre# pre# pre# pre# pre# F#event) plottype(scatter) ///
		ciplottype(rcap) together perturb(-0.325(0.13)0.325) trimlead(6) ///
		noautolegend ///
	lag_opt1(msymbol(S) color(black)) lag_ci_opt1(color(black)) ///
	lag_opt2(msymbol(O) color(gs10)) lag_ci_opt2(color(gs10)) ///
		graph_opt(title("All Workers: % Change in Earnings", size(medlarge)) ///
		xtitle("Years since wind project operation begins") xlabel(-6(1)6)  ///
		legend(order(1 "Worker-Level" 3 "County-Level") rows(1) region(style(none))) ///
		xline(-0.5, lcolor(gs8) lpattern(dash)) yline(0, lcolor(gs8)) graphregion(color(white)) bgcolor(white) ylabel(, angle(horizontal))  ///
	)	
graph save all_wrk_cty_inc2, replace
graph export all_wrk_cty_inc2.pdf, replace
graph export all_wrk_cty_inc2.png, replace


/* Figures 4 and 5: comparison by race and ethnicity, individual and county */

/* employment */

* Figure 4: workers by race and ethnicity, employment	
event_plot b_hisp_emp_trt#sd_hisp_emp_trt2 b_black_emp_trt#sd_black_emp_trt2 b_indnat_emp_trt#sd_indnat_emp_trt2 b_white_emp_trt#sd_white_emp_trt2, ///
		stub_lag(tau# tau# tau# tau#  tau# tau# L#event) ///
		stub_lead(pre# pre# pre# pre# pre# pre# F#event) plottype(scatter) ///
		ciplottype(rcap) together perturb(-0.325(0.135)0.325) trimlead(6) ///
		noautolegend ///
	lag_opt1(msymbol(+) color(gs8)) lag_ci_opt1(color(gs8)) ///
	lag_opt2(msymbol(O) color(gs5)) lag_ci_opt2(color(gs5)) ///
	lag_opt3(msymbol(Dh) color(gs12)) lag_ci_opt3(color(gs12)) ///
	lag_opt4(msymbol(S) color(black)) lag_ci_opt4(color(black)) ///
		graph_opt(title("Worker-Level by Race and Ethnicity: % Change in Employment", size(medlarge)) ///
		xtitle("Years since wind project operation begins") xlabel(-6(1)6)  ///
		legend(order(1 "Hispanic/Latino" 3 "Black" 5 "American Indian" 7 "White") rows(2) region(style(none))) ///
		xline(-0.5, lcolor(gs8) lpattern(dash)) yline(0, lcolor(gs8)) graphregion(color(white)) bgcolor(white) ylabel(, angle(horizontal))  ///
	)	
graph save race_wrk_cty_emp2, replace
graph export race_wrk_cty_emp2.pdf, replace
graph export race_wrk_cty_emp2.png, replace


/* earnings */

* Figure 5: workers by race and ethnicity, Earnings	
event_plot b_hisp_inc_trt#sd_hisp_inc_trt2 b_black_inc_trt#sd_black_inc_trt2 b_indnat_inc_trt#sd_indnat_inc_trt2 b_white_inc_trt#sd_white_inc_trt2, ///
		stub_lag(tau# tau# tau# tau#  tau# tau# L#event) ///
		stub_lead(pre# pre# pre# pre# pre# pre# F#event) plottype(scatter) ///
		ciplottype(rcap) together perturb(-0.325(0.135)0.325) trimlead(6) ///
		noautolegend ///
	lag_opt1(msymbol(+) color(gs8)) lag_ci_opt1(color(gs8)) ///
	lag_opt2(msymbol(O) color(gs5)) lag_ci_opt2(color(gs5)) ///
	lag_opt3(msymbol(Dh) color(gs12)) lag_ci_opt3(color(gs12)) ///
	lag_opt4(msymbol(S) color(black)) lag_ci_opt4(color(black)) ///
		graph_opt(title("Worker-Level by Race and Ethnicity: % Change in Earnings", size(medlarge)) ///
		xtitle("Years since wind project operation begins") xlabel(-6(1)6)  ///
		legend(order(1 "Hispanic/Latino" 3 "Black" 5 "American Indian" 7 "White") rows(2) region(style(none))) ///
		xline(-0.5, lcolor(gs8) lpattern(dash)) yline(0, lcolor(gs8)) graphregion(color(white)) bgcolor(white) ylabel(, angle(horizontal))  ///
	)	
graph save race_wrk_cty_inc2, replace
graph export race_wrk_cty_inc2.pdf, replace
graph export race_wrk_cty_inc2.png, replace
	

/* Figures 6 and 7: comparison by race and ethnicity, individuals */

/* employment */

* Figure 6: workers by sex, employment	
event_plot b_female_emp_trt#sd_female_emp_trt2 b_male_emp_trt#sd_male_emp_trt2, ///
		stub_lag(tau# tau# tau# tau#  tau# tau# L#event) ///
		stub_lead(pre# pre# pre# pre# pre# pre# F#event) plottype(scatter) ///
		ciplottype(rcap) together perturb(-0.325(0.135)0.325) trimlead(6) ///
		noautolegend ///
	lag_opt1(msymbol(O) color(black)) lag_ci_opt1(color(black)) ///
	lag_opt2(msymbol(S) color(gs10)) lag_ci_opt2(color(gs10)) ///
		graph_opt(title("Worker-Level by Sex: % Change in Employment", size(medlarge)) ///
		xtitle("Years since wind project operation begins") xlabel(-6(1)6)  ///
		legend(order(1 "Female" 3 "Male") rows(1) region(style(none))) ///
		xline(-0.5, lcolor(gs8) lpattern(dash)) yline(0, lcolor(gs8)) graphregion(color(white)) bgcolor(white) ylabel(, angle(horizontal))  ///
	)	
graph save sex_wrk_cty_emp2, replace
graph export sex_wrk_cty_emp2.pdf, replace
graph export sex_wrk_cty_emp2.png, replace	

/* earnings */

* Figure 7: workers by sex, Earnings	
event_plot b_female_inc_trt#sd_female_inc_trt2 b_male_inc_trt#sd_male_inc_trt2, ///
		stub_lag(tau# tau# tau# tau#  tau# tau# L#event) ///
		stub_lead(pre# pre# pre# pre# pre# pre# F#event) plottype(scatter) ///
		ciplottype(rcap) together perturb(-0.325(0.135)0.325) trimlead(6) ///
		noautolegend ///
	lag_opt1(msymbol(O) color(black)) lag_ci_opt1(color(black)) ///
	lag_opt2(msymbol(S) color(gs10)) lag_ci_opt2(color(gs10)) ///
		graph_opt(title("Worker-Level by Sex: % Change in Earnings", size(medlarge)) ///
		xtitle("Years since wind project operation begins") xlabel(-6(1)6)  ///
		legend(order(1 "Female" 3 "Male") rows(1) region(style(none))) ///
		xline(-0.5, lcolor(gs8) lpattern(dash)) yline(0, lcolor(gs8)) graphregion(color(white)) bgcolor(white) ylabel(, angle(horizontal))  ///
	)	
graph save sex_wrk_cty_inc2, replace
graph export sex_wrk_cty_inc2.pdf, replace
graph export sex_wrk_cty_inc2.png, replace
	

/* Figures 8 and 9: comparison by educational attainment, individuals */

/* employment */

* Figure 8: workers by educational attainment, employment	
event_plot b_nohigh_emp_trt#sd_nohigh_emp_trt2 b_highsch_emp_trt#sd_highsch_emp_trt2 b_somecoll_emp_trt#sd_somecoll_emp_trt2 b_college_emp_trt#sd_college_emp_trt2, ///
		stub_lag(tau# tau# tau# tau#  tau# tau# L#event) ///
		stub_lead(pre# pre# pre# pre# pre# pre# F#event) plottype(scatter) ///
		ciplottype(rcap) together perturb(-0.325(0.135)0.325) trimlead(6) ///
		noautolegend ///
	lag_opt1(msymbol(+) color(gs8)) lag_ci_opt1(color(gs8)) ///
	lag_opt2(msymbol(O) color(gs5)) lag_ci_opt2(color(gs5)) ///
	lag_opt3(msymbol(Dh) color(gs12)) lag_ci_opt3(color(gs12)) ///
	lag_opt4(msymbol(S) color(black)) lag_ci_opt4(color(black)) ///
		graph_opt(title("Worker-Level by Education: % Change in Employment", size(medlarge)) ///
		xtitle("Years since wind project operation begins") xlabel(-6(1)6)  ///
		legend(order(1 "No High School" 3 "High School" 5 "Some College" 7 "College") rows(2) region(style(none))) ///
		xline(-0.5, lcolor(gs8) lpattern(dash)) yline(0, lcolor(gs8)) graphregion(color(white)) bgcolor(white) ylabel(, angle(horizontal))  ///
	)	
graph save educ_wrk_cty_emp2, replace
graph export educ_wrk_cty_emp2.pdf, replace
graph export educ_wrk_cty_emp2.png, replace

/* earnings */

* Figure 9: workers by educational attainment, Earnings	
event_plot b_nohigh_inc_trt#sd_nohigh_inc_trt2 b_highsch_inc_trt#sd_highsch_inc_trt2 b_somecoll_inc_trt#sd_somecoll_inc_trt2 b_college_inc_trt#sd_college_inc_trt2, ///
		stub_lag(tau# tau# tau# tau#  tau# tau# L#event) ///
		stub_lead(pre# pre# pre# pre# pre# pre# F#event) plottype(scatter) ///
		ciplottype(rcap) together perturb(-0.325(0.135)0.325) trimlead(6) ///
		noautolegend ///
	lag_opt1(msymbol(+) color(gs8)) lag_ci_opt1(color(gs8)) ///
	lag_opt2(msymbol(O) color(gs5)) lag_ci_opt2(color(gs5)) ///
	lag_opt3(msymbol(Dh) color(gs12)) lag_ci_opt3(color(gs12)) ///
	lag_opt4(msymbol(S) color(black)) lag_ci_opt4(color(black)) ///
		graph_opt(title("Worker-Level by Education: % Change in Earnings", size(medlarge)) ///
		xtitle("Years since wind project operation begins") xlabel(-6(1)6)  ///
		legend(order(1 "No High School" 3 "High School" 5 "Some College" 7 "College") rows(2) region(style(none))) ///
		xline(-0.5, lcolor(gs8) lpattern(dash)) yline(0, lcolor(gs8)) graphregion(color(white)) bgcolor(white) ylabel(, angle(horizontal))  ///
	)	
graph save educ_wrk_cty_inc2, replace
graph export educ_wrk_cty_inc2.pdf, replace
graph export educ_wrk_cty_inc2.png, replace



	


